# Copyright (c) 2007 Fabio Makoto Akita
# 
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
# 
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

# Author: AkitaOnRails (www.akitaonrails.com)
# Support: Surgeworks LLC (www.surgeworks.com)

require "net/http"
require "net/https"
require 'digest/sha1'
require 'uuidtools'
require 'yaml'
require 'activerecord_fixes'
require 'userstamp'
require 'acts_as_replica'

ActiveRecord::Base.send(:include, ActsAsReplica)
ActiveRecord::Base.send(:include, ActiveRecord::Userstamp)

ActionController::Base.param_parsers[Mime::YAML] = :yaml
ActionController::Base.send(:include, ActionController::UserStamp)

# loads or creates a new SyncSetting for the system
# ideally this should be reloaded right before needed
# $SYNC_CONFIG should be always global to the process
# as ActionPack isn't thread-safe anyway, having this object in the context
# of a single HttpRequest life-cycle shouldn't be bad
begin
  $SYNC_CONFIG = ActiveRecord::Base.load_config
rescue => e
  $SYNC_CONFIG = {}
  RAILS_DEFAULT_LOGGER.error "Error reading configuration from database. Probably no tables found yet. Migrations?"
end